#################################################################
# @Description: 用例名称：CPU热插拔，测试目的：在硬件支持情况下，支持CPU热插拔
# @Date : 2023-11-25
# @Last Modified by :
# @Last Modified time:
#################################################################
#! /bin/bash
set -euo pipefail
res=0
export LC_ALL=en_US.UTF-8
# 前提条件硬件支持热插拔
check_result=`lscpu | grep "On-line CPU(s) list:" |awk '{print $4}'`
if [ -z "$check_result" ];then
    echo -e "\033[31m-----------------Hardware Unsupport----------------\033[0m"
    exit 1
fi

read -p "请输入热插拔CPU编号：(输入数字范围："$check_result",不要输入0) " X
# 2.下线cpu
echo "下线CPU${X}"
echo 0 > /sys/devices/system/cpu/cpu$X/online #X为第一步查出来的cpu编号
# 查看cpu是否下线成功
echo "已下线CPU：`grep $X /sys/devices/system/cpu/offline`" || res=1
# 3.上线cpu
echo "上线CPU${X}"
echo 1 > /sys/devices/system/cpu/cpu$X/online || res=1
sleep 1
# 查看cpu是否上线成功
grep $X /sys/devices/system/cpu/offline && res=1
echo "当前在线的CPU列表为：`cat /sys/devices/system/cpu/online`" || res=1
# 判断用例执行是否成功
[ "$res" = "0" ] && echo -e "\033[32m-----------------test PASSED----------------\033[0m" || echo -e "\033[31m-----------------test FAILD----------------\033[0m"
unset LC_ALL